﻿/********************************************************************************
    Copyright (C) Binod Nepal, Planet Earth Solutions Pvt. Ltd., Kathmandu.
	Released under the terms of the GNU General Public License, GPL, 
	as published by the Free Software Foundation, either version 3 
	of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace MixNP.BusinessLayer.Helpers
{
    public static class RequestForm
    {
        public static string GetFormValue(string key, System.Web.UI.Page page)
        {
            return page.Server.HtmlEncode(page.Request.Form[key]);
        }

        public static string GetUserControlFormValue(string key, System.Web.UI.Page page)
        {
            key = key + "$" + key;
            return page.Server.HtmlEncode(page.Request.Form[key]);
        }

        public static string GetUserControlFormRangeValue(string key, System.Web.UI.Page page)
        {
            key = key + "$" + key + "Range";
            return page.Server.HtmlEncode(page.Request.Form[key]);
        }

        public static string GetUserControlFormCheckBoxSelection(string key, System.Web.UI.Page page)
        {
            key = key + "$" + key;
            string retVal = string.Empty;

            if (page.Request.Form.Count > 0)
            {
                foreach (string name in page.Request.Form)
                {
                    if (!string.IsNullOrWhiteSpace(name))
                    {
                        if (name.StartsWith(key))
                        {
                            retVal = retVal + page.Request.Form[name] + ",";
                        }                    
                    }
                }
            }
            if (retVal.EndsWith(","))
            {
                retVal = retVal.TrimEnd(',');
            }

            return retVal;
        }
    }
}
